package com.boco.action;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.boco.dao.GetEMR_ZY_FYMXData;
import com.boco.dao.SentData;
import com.boco.entity.EMR_ZY_FYMX;

public class InsertEMR_ZY_FYMXDataAction {
	private static final Log log = LogFactory.getLog(InsertEMR_ZY_FYMXDataAction.class);
	public  String insertData(){
		String url = "http://fasong.cdxp.csb/json/dzbl4";
		String resule = null;
		List<EMR_ZY_FYMX> list = new ArrayList<EMR_ZY_FYMX>();
		list = GetEMR_ZY_FYMXData.getData();
		
	    log.info("########################################");
	    log.info("数据总条数："+list.size());
	    log.info("########################################");
		String userName = "dzbl4";
		String password = "322dfbf9048445cabb06cbf24e64cdcf";
		EMR_ZY_FYMX temp = null;
		
		for(int i=0;i<list.size();i++){
			String param = null;
			temp = list.get(i);
			//log.info(temp.getXM());
			//按照身份证删除已经存在的值。
			param = "{\"SQL\":\"delete  EMR_ZY_FYMX where ZYH='"+
					temp.getZYH()
					+"' and ZZJGDM = '"+temp.getZZJGDM()+"'"
					
			
					+ "\", \"ANNOTION\":\"cdxplogs\"}";
			resule = SentData.sendPost(url, param, userName, password);
			log.info("删除结果："+resule);
			param = "{\"SQL\":\"INSERT INTO EMR_ZY_FYMX ("
					+ "HZZSYH,"
					+ "DQMC,"
					+ "DQDM,"
					+ "ZZJGMC,"
					+ "ZZJGDM,"
					+ "SJMJ,"
					+ "ZYH,"
					+ "BAH,"
					+ "YEID_HIS,"
					+ "JLH_HIS,"
					+ "ZYKSDM,"
					+ "ZYKSMC,"
					+ "KSDM_HIS,"
					+ "KSMC_HIS,"
					+ "XXLY,"
					+ "ZYYZ,"
					+ "XMFLDM,"
					+ "ZYFYLBMC,"
					+ "ZYFYLBDM,"
					+ "XMDM,"
					+ "DMMC,"
					+ "XMDM_HIS,"
					+ "XMMC_HIS,"
					+ "XMDW,"
					+ "XMDJ,"
					+ "XMSL,"
					+ "XMJE,"
					+ "CJSJ,"
					+ "JFSJ,"
					+ "JSSJ,"
					+ "JSCS,"
					+ "JSPHJ,"
					+ "SFKSS,"
					+ "SFGJJY,"
					+ "SFJMYP,"

					+ "BCRQ,"
					+ "ORGCODE,"
					+ "AREACODE,"
					+ "UPLOADTIME,"
					+ "SOURCEID"
					+ ") VALUES("
					+ "'" + checkStr(temp.getHZZSYH()) + "'," 
					+ "'" + checkStr(temp.getDQMC()) + "'," 
					+ "'" + checkStr(temp.getDQDM()) + "'," 
					+ "'" + checkStr(temp.getZZJGMC()) + "'," 
					+ "'" + checkStr(temp.getZZJGDM()) + "',"
					+ "'" + checkStr(temp.getSJMJ()) + "'," 
					+ "'" + checkStr(temp.getZYH()) + "'," 
					+ "'" + checkStr(temp.getBAH()) + "'," 
					+ "'" + checkStr(temp.getYEID_HIS()) + "'," 
					+ "'" + checkStr(temp.getJLH_HIS()) + "'," 
					+ "'" + checkStr(temp.getZYKSDM()) + "'," 
					+ "'" + checkStr(temp.getZYKSMC()) + "',"
					+ "'" + checkStr(temp.getKSDM_HIS()) + "',"
					+ "'" + checkStr(temp.getKSMC_HIS()) + "'," 
					+ "'" + checkStr(temp.getXXLY()) + "'," 
					+ "'" + checkStr(temp.getZYYZ()) + "'," 
					+ "'" + checkStr(temp.getXMFLDM()) + "'," 
					+ "'" + checkStr(temp.getZYFYLBMC()) + "'," 
					+ "'" + checkStr(temp.getZYFYLBDM()) + "'," 
					
					+ "'" + checkStr(temp.getXMDM()) + "'," 
					+ "'" + checkStr(temp.getDMMC()) + "'," 
					+ "'" + checkStr(temp.getXMDM_HIS()) + "',"
					+ "'" + checkStr(temp.getXMMC_HIS()) + "',"
					+ "'" + checkStr(temp.getXMDW()) + "'," 
					+ "" + checkStr(temp.getXMDJ()) + "," 
					+ "" + checkStr(temp.getXMSL()) + "," 
					+ "" + checkStr(temp.getXMJE()) + "," 
					+ "to_date('" + checkStr(temp.getCJSJ()) + "','yyyy-MM-dd HH24:mi:ss')," 
					+ "to_date('" + checkStr(temp.getJFSJ()) + "','yyyy-MM-dd HH24:mi:ss')," 
					
					+ "to_date('" + checkStr(temp.getJSSJ()) + "','yyyy-MM-dd HH24:mi:ss'),"
					+ "'" + checkStr(temp.getJSCS()) + "',"
					+ "'" + checkStr(temp.getJSPHJ()) + "'," 
					+ "'" + checkStr(temp.getSFKSS()) + "'," 
					+ "'" + checkStr(temp.getSFGJJY()) + "'," 
					+ "'" + checkStr(temp.getSFJMYP()) + "'," 

					+ "to_date('" + checkStr(temp.getBCRQ()) + "','yyyy-MM-dd HH24:mi:ss'),"
					+ "'" + checkStr(temp.getORGCODE()) + "'," 
					+ "'" + checkStr(temp.getAREACODE()) + "'," 
					+ "sysdate," 
					+ "'dzbl4'" 
					+ ")\", \"ANNOTION\":\"cdxplogs\"}";
					resule = SentData.sendPost(url, param, userName, password);
					log.info(resule);
					
		}
		log.info("上传完成！");
		return resule;
		
	
		
	}
	
	public static String checkStr(Object obj){
		if (obj== null){
			obj = "";
		}
		return (String) obj;
	}
	
	
}
